package com.offcn.movie.dao;

import com.offcn.bean.ConditionBean;
import com.offcn.bean.Movietable;
import com.offcn.bean.Performerdetailtable;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import java.util.List;

public interface MovieDao {
    //保存电影信息
    @Insert("insert into movietable(moviename,time,url,imagepath,saveimagepath,score,status,source) value(#{moviename},#{time},#{url},#{imagepath},#{saveimagepath},#{score},#{status},#{source})")
    @SelectKey(keyProperty = "id",keyColumn = "id",resultType = int.class,before = false,statement = "select last_insert_id()")
    void insert(Movietable movietable);


    @Select("select * from movietable limit #{i}")
    List<Movietable> selectMovieList(int i);


    @Select("select * from performerdetailtable limit #{i}")
    List<Performerdetailtable> selectPerformerList(int i);

    //后台电影列表
    @Select("\t<script>\n" +
            "\t\tSELECT m.*,md.*\n" +
            "\t\tFROM movietable m JOIN moviedetailtable md\n" +
            "\t\tON m.id = md.id\n" +
            "\t\t<where>\n" +
            "\t\t\t<if test=\"conditionBean != null\">\n" +
            "\t\t\t\t<if test=\"conditionBean.area != null and conditionBean.area.length > 0\">\n" +
            "\t\t\t\t\tand md.categroy LIKE concat('%',#{conditionBean.area},'%')\n" +
            "\t\t\t\t</if>\n" +
            "\t\t\t\t<if test=\"conditionBean.type != null and conditionBean.type.length > 0\">\n" +
            "\t\t\t\t\tand md.categroy LIKE concat('%',#{conditionBean.type},'%')\n" +
            "\t\t\t\t</if>\n" +
            "\t\t\t\t<if test=\"conditionBean.style != null and conditionBean.style.length > 0\">\n" +
            "\t\t\t\t\tand md.categroy LIKE concat('%',#{conditionBean.style},'%')\n" +
            "\t\t\t\t</if>\n" +
            "\t\t\t\t<if test=\"conditionBean.mname != null and conditionBean.mname.length > 0\">\n" +
            "\t\t\t\t\tand m.moviename LIKE concat('%',#{conditionBean.mname},'%')\n" +
            "\t\t\t\t</if>\n" +
            "\t\t\t\t<if test=\"conditionBean.fromS != null and conditionBean.year != null and conditionBean.year.length > 0\">\n" +
            "\t\t\t\t\t<choose>\n" +
            "\t\t\t\t\t\t<when test=\"conditionBean.fromS eq 'back'\">\n" +
            "\t\t\t\t\t\t\tand SUBSTR(m.imagepath,31,4) like concat('%',#{conditionBean.year},'%')\n" +
            "\t\t\t\t\t\t</when>\n" +
            "\t\t\t\t\t\t<when test=\"conditionBean.fromS eq 'front'\"></when>\n" +
            "\t\t\t\t\t</choose>\n" +
            "\t\t\t\t</if>\n" +
            "\t\t\t</if>\n" +
            "\t\t</where>\n" +
            "\t</script>")
    List<Movietable> selectMovieList1(@Param("conditionBean") ConditionBean conditionBean1);

    //电影数量
    @Select("select count(*) from movietable")
    int countMovie();


}
